# -*- coding: utf-8 -*-

###################
#   miniTH
#   This program serves for serial change of photos size, to put watermarks
#   and at the same time for making thumbnails.
#   It can be useful for quick processing of big amount of pictures in order to put
#   them in web galleries or on websites.
#   Copyright (C) 2011 DooBLER
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
###################

###################
# svn: $Id: MyHistogramWidget.py 19 2011-08-15 13:41:38Z MrDooBLER@gmail.com $
# Author: DooBLER http://doobler.net
###################


from PySide import QtCore
from PySide import QtGui

import random

class MyHistogramWidget(QtGui.QWidget):

    def __init__(self, parent, ahistogram=[]):
        QtGui.QWidget.__init__(self, parent)

        self._histogram = ahistogram

        random.randrange(0, 200)

        self.red = [random.randrange(0, 200) for e in range(256)]
        self.green = [random.randrange(0, 200) for e in range(256)]
        self.blue = [random.randrange(0, 200) for e in range(256)]

        self.pen = QtGui.QPen(QtGui.QBrush(QtGui.QColor(255, 0, 0, 255), QtCore.Qt.SolidPattern), 1)


    def paintEvent(self, ev):
        p = QtGui.QPainter(self)

        p.setPen(self.pen)

        #aaarect = QtCore.QRect(self.rect().left(), self.rect().top(), self.rect().width()+10, 40)

        #p.fillRect(aaarect, QtGui.QBrush(QtCore.Qt.red, QtCore.Qt.Dense2Pattern))

        bottom = self.rect().top()+300

        for i in range(256):

            self.pen = QtGui.QPen(QtGui.QBrush(QtGui.QColor(255, 0, 0, 86), QtCore.Qt.SolidPattern), 1)
            p.setPen(self.pen)
            p.drawLine(i, bottom, i, bottom-self.red[i])
            self.pen = QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 255, 0, 86), QtCore.Qt.SolidPattern), 1)
            p.setPen(self.pen)
            p.drawLine(i, bottom, i, bottom-self.green[i])
            self.pen = QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 255, 86), QtCore.Qt.SolidPattern), 1)
            p.setPen(self.pen)
            p.drawLine(i, bottom, i, bottom-self.blue[i])
